$().ready(function(){
	$("[data-href]").on("click",function(){location.href=$(this).data("href");})
	  $(".Assets-right").click(function(){
        var i=$(this).data("toggle-more");
        var widthPos=parseInt($("body").css("width"))*0.55;
        if(i==0){
        	$(".Assets_body").css("width",widthPos)
            $(".right-aside").animate({right:"0"},200);
            $(this).data("toggle-more",1);
            $("#asideImg").attr("src","../img/close-aside.png")
        }else{
        	$(this).data("toggle-more",0);
        	var widthBody="-"+$("body").css("width")
            $(".right-aside").animate({right:widthBody},200);
            
             $("#asideImg").attr("src","../img/head-more.png");
        }
    })
    
    //钱包选择激活
    //钱包地址
	$.ajax({ 
		url:"/app/coldwallet/querywallet",
		dataType:"JSON",
		success:function(r){
			console.log(r)
			for(var i=0,data=r.list,len=data.length,html="";i<len;i++){
	           html+=` <li><a data-wltname=${data[i].address} data-status=${data[i].walletstatus} data-wltid=${data[i].id}>
	        	   <i class="icon Money_Name1"></i> <em>${data[i].walletname}</em> 
	        	   <span  class="pull-right wallet-right-img"></span>
	        	   </a></li>`
			}
			html+="<li class='aside_line'></li>";
			$(".address-xz").html(html);
			var initWallet=$(".address-xz li").eq(0);
			initWallet.addClass("curr");
			var wltname=initWallet.find("a").data("wltname").toString();
			$("#drees_code").html(wltname);
			var wltStart=wltname.substr(0,10),wltend=wltname.substr(wltname.length-12,wltname.length); 
			$(".js-assets-code").text(wltStart+"……"+wltend);
			var nickname=initWallet.find("em").text();
			 new QRCode("qrcode", {  
                 text: nickname,  
                 width: 250,  
                 height: 250,    
             }); 	
			$("#moneyName").html(nickname);
			$("#token_name").html(nickname);
			var init=data[0];
			var add=init.address,addid=init.id;
			$(".Assets_crate #moneyName").data("address",add);
			$(".Assets_crate #moneyName").data("wltid",addid);
			var adddd=$(".Assets_crate #moneyName").data("wltid");
			//钱包状态 0 没有备份 1 备份了
			var backup=initWallet.find("a").data("status");
			backup==0?$(".back-up").css("display","inline"):$(".back-up").css("display","none");
			//钱包下面的账户金额
			$.ajax({
				url:"/app/token_quotation/select",
				data:{"address":add},
				success:function(r){
					console.log(r);
					if(r.code==0){
						if(r.list.length==0){
							$("#assetAll").html('<li class="fix-clear" ><span class="pull-left"><img src="../img/ether.png" alt=""/><span>ETH</span></span><span>0.00000</span> </li>');
							return true;}
						var data=r.list;
						var html='<li class="fix-clear" ><span class="pull-left"><img src="../img/ether.png" alt=""/><span>ETH</span></span><span>0.00000</span> </li>';
						for(var i=0;i<data.length;i++){
							html+=`<li class="fix-clear">
						                <span class="pull-left">
						                    <img src="../img/ether.png" alt=""/>
						                    <span>${data[i].tokenname}</span></span>
						                <span>0.00000</span>
						            </li>`
						}
						$("#assetAll").html(html);
					}
				}
			})
			
			$(".address-xz").on("click","li",function(){
				if(!$(this).hasClass("aside_line")){
					$(this).addClass("curr").siblings(".curr").removeClass("curr");
					var wltname=$(this).find("a").data("wltname").toString();
					$("#drees_code").html(wltname);
					var wltStart=wltname.substr(0,10),wltend=wltname.substr(wltname.length-12,wltname.length);  
					$(".js-assets-code").text(wltStart+"……"+wltend);
					var nickname=$(this).find("em").text();
					$("#token_name").html(nickname);
					$(".Money_Name").html(nickname);
					$("#qrcode").empty();
					new QRCode("qrcode", {  
		                 text: nickname,  
		                 width: 250,  
		                 height: 250,    
		             }); 
					//钱包下面的账户金额
					$.ajax({
						url:"/app/token_quotation/select",
						data:{"address":wltname},
						success:function(r){
							if(r.code==0){
								if(r.list.length==0){
									$("#assetAll").html('<li class="fix-clear" ><span class="pull-left"><img src="../img/ether.png" alt=""/><span>ETH</span></span><span>0.00000</span> </li>');
									return true;}
								var data=r.list;
								var html="";
								for(var i=0;i<data.length;i++){
									html+=`<li class="fix-clear">
								                <span class="pull-left">
								                    <img src="../img/ether.png" alt=""/>
								                    <span>${data[i].tokenname}</span></span>
								                <span>0.00000</span>
								               
								            </li>`
								}
								$("#assetAll").html(html);
							}
							
						}
					})
					//钱包状态 0 没有备份 1 备份了
					var backup=$(this).find("a").data("status");
					if(backup==0){
						$(".back-up").css("display","inline");
						var address=$(this).find("a").data("wltname");
						var wltid=$(this).find("a").data("wltid");
						//console.log(address,wltid);
						$(".Money_Name").data("address",address);
						$(".Money_Name").data("wltid",wltid);
					}else{$(".back-up").css("display","none");}
					//钱包下面的金额
					
				}
			})
		}
	})
    $(".back-up").click(function(){
    	//console.log($(".Money_Name").data("address"),$(".Money_Name").data("wltid"));
    	var codeWallet={}; 
    	codeWallet.address=$(".Money_Name").data("address");
    	codeWallet.walletid=$(".Money_Name").data("wltid");
    	codeWallet=JSON.stringify(codeWallet);
    	sessionStorage.setItem("codeAdd",codeWallet);
    	location.href="./Token_Assets/Token_append_money2.html";
    })
    
})
